#include<stdio.h>
#include<stdlib.h>
#define Max(a,b) (a>b ? a:b)
typedef struct TNode *BinTree;
typedef int ElementType;
struct TNode
{
    ElementType Data;
    BinTree Left, Right;
    int Height;
};

BinTree Insert(BinTree BST, ElementType X)
{
    if (!BST)
    { 
        BST = (BinTree)malloc(sizeof(struct TNode));
        BST->Data = X;
        BST->Left = NULL;
        BST->Right = NULL;
        BST->Height = 1;
    }
    else
    {
        if(X < BST->Data)
        {
            BST->Left = Insert(BST->Left, X);
            BST->Left->Height = BST->Height + 1;
        }
        else if(X >= BST->Data)
        {
            BST->Right = Insert(BST->Right, X);
            BST->Right->Height = BST->Height + 1;
        }
    }
    return BST;
}

void PrintLeaf(BinTree BST)
{
    if(BST) 
    {
        if(!BST->Left && !BST->Right)
            printf("%d %d\n", BST->Data, BST->Height);
        PrintLeaf(BST->Left);
        PrintLeaf(BST->Right);
    }
}

int main()
{
    int n, x;
    BinTree BST = NULL;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
    {
        scanf("%d", &x);
        BST = Insert(BST, x);
    }
    PrintLeaf(BST);
    return 0;
}